let express = require('express'),
    socket = require('socket.io');

//App的设置
let app = express(),
    server = app.listen(7000, () => {
        console.log('正在监听7000端口')
    })

//静态文件
app.use(express.static('public'));

//socket的设置
let io = socket(server);

//监听客户端连接,回调函数会传递本次连接的socket
io.on('connection', (socket) => {
    console.log('scoket连接已建立', socket.id);
    socket.on('chat', (data) => {
        io.sockets.emit('chat', data);
    })
    //typing：正在输入
    socket.on('typing', (data) => {
        socket.broadcast.emit('typing', data); //broadcast：广播
    })
})